<?php
/* PHP SDK
 * @version 2.0.0
 * @author connect@qq.com
 * @copyright © 2013, Tencent Corporation. All rights reserved.
 * 
 * 
 * 缓存数据
 */

require_once(CLASS_PATH."ErrorCase.class.php");
class Recorder{
    private static $data;#arr
    private $inc;#config
    private $error;


//对象初始函数
    public function __construct(){
        $this->error = new ErrorCase();

        //-------读取配置文件
        $incFileContents = file(API_ROOT."comm/inc.php");
        //忽略第一行的php代码
        $incFileContents = $incFileContents[1];
        //将str转化为arr
        $this->inc = json_decode($incFileContents);
        if(empty($this->inc)){
            $this->error->showError("20001");
        }
        
       //QC_userData不存在就new一个arr
         if(empty($_SESSION['QC_userData'])){
            self::$data = array();
        }
        //存在就将QC_userData赋值给static
        else{
            self::$data = $_SESSION['QC_userData'];
        }
		
    }


/*
 * 对象销毁时执行
 * 
 * 将static加载到session
 */
  function __destruct(){
        $_SESSION['QC_userData'] = self::$data;
    }
    
//static arr
    public function write($name,$value){
        self::$data[$name] = $value;
    }

    public function read($name){
        if(empty(self::$data[$name])){
            return null;
        }else{
            return self::$data[$name];
        }
    }
 public function delete($name){
        unset(self::$data[$name]);
    }
    
    
    

/*
 * 获取config参数
 * 
 * 参数名不存在就返回null
 * 
 */
    public function readInc($name){
        if(empty($this->inc->$name)){
            return null;
        }else{
            return $this->inc->$name;
        }
    }

   

   
}
